<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    写一个function，清除字符串前后的空格（兼容所有浏览器）
</body>
<script>
    if (!String.prototype.trim) {
        String.prototype.trim = function () {
            return this.replace(/^\s+/, "").replace(/\s+$/, "");
        }
    }


    // test the function
    var str = " \t\n test string ".trim();
    alert(str == "test string"); // alerts "true"


    function trim(str) {
	if (str & typeof str === "string") {
		return str .replace(/(As*)1(s*)$/g,""); //去除前后空白符
	}
}

</script>

</html>